namespace Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;
    using OnlineTestsModels;

    public sealed class Configuration : DbMigrationsConfiguration<OnlineTestsDataLayer.TestsContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
            ContextKey = "OnlineTestsDataLayer.TestsContext";

        }

        protected override void Seed(OnlineTestsDataLayer.TestsContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //

            //SeedUsers(context);

        }

        private static void SeedUsers(OnlineTestsDataLayer.TestsContext context)
        {
            var teacherRole = new Role() { RoleName = "Teacher" };
            var studentRole = new Role() { RoleName = "Student" };

            context.Roles.Add(teacherRole);
            context.Roles.Add(studentRole);
            context.Users.Add(new User()
            {
                Role = studentRole,
                Username = "TestStudent",
                Password = "1234",
            });
            context.Users.Add(new User()
                {
                    Role = teacherRole,
                    Username = "TestTeacher",
                    Password = "1234",
                });
            context.SaveChanges();
        }
    }
}
